/////////////////////////////////////////////////////////////////////
//
//  MOE Framework (Meta Object Encapsulation Framework)
//
//  Original Author: Wiksy Wang, 2011
//
/////////////////////////////////////////////////////////////////////

#include "NamePathRef.h"

#include <boost/assert.hpp>

namespace MOE
{

namespace Name
{

NamePathRef::NamePathRef(const NamePath& obj, size_t startIndex, size_t endIndex)
	: _obj(obj)
	, _startIndex(startIndex)
	, _endIndex(endIndex)
{
	BOOST_ASSERT(_startIndex <= _endIndex);
	if (_endIndex > _obj._splitCount)
	{
		_endIndex = _obj._splitCount;
	}
}

NamePathRef::NamePathRef(const NamePathRef& other, size_t startIndex, size_t endIndex)
	: _obj(other._obj)
	, _startIndex(startIndex + other._startIndex)
	, _endIndex(endIndex + other._startIndex)
{
	BOOST_ASSERT(_startIndex <= _endIndex);
	if (_endIndex > other._endIndex)
	{
		_endIndex = other._endIndex;
	}
}

RawByteVectorRef NamePathRef::GetSubPath(size_t index) const
{
	return _obj.GetSegment(_startIndex + index, _endIndex);
}

RawByteVectorRef NamePathRef::GetSegment(size_t startIndex, size_t endIndex) const
{
	return _obj.GetSegment(_startIndex + startIndex, std::min(_startIndex + endIndex, _endIndex));
}

}

}
